package com.chainyoung.component_tmperson.ui.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chainyoung.common.appcommon.hdwallet.ExchangeCalculator;
import com.chainyoung.common.appcommon.hdwallet.WalletServerConstant;
import com.chainyoung.common.utils.ConvertUtils;
import com.chainyoung.common.utils.StringUtil;
import com.chainyoung.common.utils.TimeUtils;
import com.chainyoung.component_tmperson.R;
import com.chainyoung.component_tmperson.entity.RechargeRecord;
import com.chainyoung.router.RouterConstants;
import com.chainyoung.router.RouterUtils;

import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import static com.chainyoung.common.constant.CommonStringConstants.URL;


/**
 * 2018/7/25 9:49
 * Created by FREECSDN on 2018/7/25.
 */
public class MakeCashRecordAdapter extends BaseQuickAdapter<RechargeRecord, BaseViewHolder> {


    SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    SimpleDateFormat sd1 = new SimpleDateFormat("HH:mm");
    SimpleDateFormat sd2 = new SimpleDateFormat("yyyy-MM-dd");
    // private int type=1;

    public MakeCashRecordAdapter(@Nullable List<RechargeRecord> data) {
        super(R.layout.layout_make_cash_item, data);

    }


    public MakeCashRecordAdapter(@Nullable List<RechargeRecord> data, Context context) {
        super(R.layout.layout_hdwallet_transaction_item, data);
        //  this.type=type;
        mContext = context;
    }


    @Override
    protected void convert(BaseViewHolder helper, RechargeRecord item) {


//        helper.setText(R.id.tv_time, sd.format(new Date(item.getAddtime() * 1000)));
//        helper.setText(R.id.tv_recharge_num, item.getNum());
//        helper.setText(R.id.tv_real_num, item.getMum());
//        helper.setText(R.id.tv_status, item.getStatus() == 0 ? mContext.getString(R.string.tmperson_in_progress) : mContext.getString(R.string.tmperson_success));


        helper.setText(R.id.tv_type, item.getType() == 2 ? mContext.getString(R.string.tmperson_withdraw) : mContext.getString(R.string.tmperson_charge));

        Date transactionTime = new Date(item.getAddtime() * 1000);
        int isYesterday = 1;
        boolean isSuccessed = item.getStatus() == 1;
        try {
            isYesterday = TimeUtils.isYeaterday(transactionTime, new Date());
        } catch (ParseException e) {
            e.printStackTrace();
        }

        helper.setText(R.id.tv_time, isSuccessed ? sd.format(transactionTime) : "处理中");
        helper.setTextColor(R.id.tv_time, isSuccessed ? ContextCompat.getColor(mContext, R.color._7e8da6) : ContextCompat.getColor(mContext, R.color._F95A54));

        ((ImageView) helper.getView(R.id.iv_type)).setImageResource(item.getType() == 2 ? R.mipmap.ic_type_send : R.mipmap.ic_type_recieve);

        //helper.setText(R.id.tv_recharge_num, item.getValue().divide(ExchangeCalculator.ONE_ETHER, 8, RoundingMode.DOWN).toPlainString());

        helper.setText(R.id.tv_real_num, item.getNum());
        helper.setTextColor(R.id.tv_real_num, item.getType() == 2 ? ContextCompat.getColor(mContext, R.color._333333) : ContextCompat.getColor(mContext, R.color._4486f5));

        String addr = TextUtils.isEmpty(item.getUsername()) ? "" : item.getUsername().substring(0, 4) + "...." + item.getUsername().substring(item.getUsername().length() - 4);

        helper.setText(R.id.tv_addr, item.getType() == 2 ? "提到:" + addr : "来自：" + addr);


    }


}
